package com.xyy.yueshijia.shopping;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.xyy.yueshijia.MainActivity;
import com.xyy.yueshijia.R;

import java.util.Map;
import java.util.Set;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    private UMShareAPI umShareAPI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        umShareAPI = UMShareAPI.get(this);
        findViewById(R.id.shop_weibo1).setOnClickListener(this);
        findViewById(R.id.shop_login_yanzhengma).setOnClickListener(this);
        findViewById(R.id.shop_login_back).setOnClickListener(this);
        findViewById(R.id.shop_login_btn).setOnClickListener(this);

        //友盟分享
        PlatformConfig.setSinaWeibo("1982598855", "ae082610110b61507f1d5c401120d0d3");
        Config.DEBUG = true;
        Config.REDIRECT_URL = "http://sns.whalecloud.com/sina2/callback";


    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            //登陆页,微博图片
            case R.id.shop_weibo1:
                umShareAPI.getPlatformInfo(LoginActivity.this, SHARE_MEDIA.SINA, new UMAuthListener() {
                    @Override
                    public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
                        Toast.makeText(LoginActivity.this, "控制台已经获得数据", Toast.LENGTH_SHORT).show();
                        Set<Map.Entry<String, String>> entries = map.entrySet();
                        for (Map.Entry<String, String> entry : entries) {
                            Log.e("========", "key:" + entry.getKey() + ",value:" + entry.getValue());
                        }

                        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                        startActivity(intent);
                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {

                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media, int i) {

                    }
                });
                //登陆页的验证码跳到注册页
            case R.id.shop_login_yanzhengma:
                Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
                startActivity(intent);
                finish();
                break;

                //登陆页返回主页
            case R.id.shop_login_back:
                Intent login_mainty = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(login_mainty);

        }
    }
}
